package com.jian.mall.produce.web;

import com.jian.mall.produce.entity.CategoryEntity;
import com.jian.mall.produce.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/produce")
public class IndexPageController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/level1category")
    @ResponseBody
    public List<CategoryEntity> getLevel1Category() {
        return categoryService.getLevel1Category();
    }

    @GetMapping({"/", "/index.html"})
    public String indexPage(Model model) {
        List<CategoryEntity> catList = categoryService.getLevel1Category();
        model.addAttribute("categoryList", catList);
        return "index";
    }

    @GetMapping({"/item.html", "/item"})
    public String itemPage(Model model) {
        return "item";
    }

}
